import java.util.concurrent.atomic.AtomicReference;

/**
 * @author wcj
 * @Date 2021/6/17 15:19
 * @Version 1.0
 */
public class AtomicReferenceTest {

    public static void main(String[] args) {
        AtomicReference<User> userAtomicReference = new AtomicReference<>();
        User wcj = new User("wcj", 25);
        userAtomicReference.set(wcj);
        User bss = new User("bss", 27);
        userAtomicReference.compareAndSet(wcj, bss);
        System.out.println(userAtomicReference.get().getName());
        System.out.println(userAtomicReference.get().getAge());
    }

}

class User {

    private String name;

    private Integer age;

    public User(String name, Integer age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public Integer getAge() {
        return age;
    }
}
